<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UserRegisterFormHandler
 *
 * @author Animus Inc.
 */
class UserRegisterFormHandler {
    
    private $_form;
    
    private $_attributes;
    
    public function setForm(Form $_form){
        
        $this->_form    =   $_form;
        
    }
    
    public function handleForm(){
        
        $form = $this->_form;
        $method = $form->getMethod();
        $attributes = array();
        $array = array();
        $flag = false;
       
        switch($method){
            
            case("post"||"POST"):
                
             if( isset($_POST["_fname"]) && isset($_POST["_lname"]) && isset($_POST["_pass"]) && isset($_POST["_email"]))
             {
              var_dump( $form->setFieldValue("_fname",$_POST["_fname"]));
              $form->setFieldValue("_lname",$_POST["_lname"]);
              $form->setFieldValue("_pass",$_POST["_pass"]);
              $_email = $form->setFieldValue("_email",$_POST["_email"]);
              $flag = $form->validate();
              $attributes["_user_id"] = md5($_email);
              $attributes["_salt"] = "test";
              $attributes["_reg_time"] = microtime();
              $attributes["_ver_status"] = "test";
              $attributes["_ver_date"] = "test";
              $array["_ver_key"] = "test";
              $array = $form->getFields();
              
              foreach($array as $object)
              {
                  $attributes[$object->getName()] = $object->getValue();
              }   
              
             }

            break;
                
           case("get"||"GET") : 
             if(isset($_GET["_fname"]) && isset($_GET["_lname"]) && isset($_GET["_pass"]) && isset($_GET["_email"]))
             {
              $form->setFieldValue("_fname",$_GET["_fname"]);
              $form->setFieldValue("_lname",$_GET["_lname"]);
              $form->setFieldValue("_pass",$_GET["_pass"]);
              $_email = $form->setFieldValue("_email",$_GET["_email"]);
              $flag = $form->validate();
              $array["_user_id"] = md5($_email);
              $array["_salt"] = "test";
              $array["_reg_time"] = microtime();
              $array["_ver_status"] = "test";
              $array["_ver_date"] = "test";
              $array["_ver_key"] = "test";
              $array = $form->getFields();
              foreach($array as $object)
              {
                  $attributes[$object->getName()] = $object->getValue();
              }
            }  
           
           break;
        }
        if($flag) $this->_attributes = $attributes;
        return  $flag;
    }
    
    public function getAttributes(){
        
       return $this->_attributes;
        
    }
}

?>
